package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ClientBean;
import com.project.mapper.IClientMapper;
import com.project.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户实现类
 */

@Service
public class ClientImplServiceImpl implements IClientService {

    @Autowired
    private IClientMapper mapper;
    @Override
    public IPage<ClientBean> findByItem(Integer pageNO, String name, String manage) {
        QueryWrapper<ClientBean> qw = new QueryWrapper<>();
        if (name!=null&&name.length()!=0){
            qw.like("c_name",name);
        }
        if (manage!=null&&manage.length()!=0){
            qw.like("c_manage",manage);
        }
        return mapper.selectPage(new Page(pageNO,3),qw);
    }

    @Override
    public void add(ClientBean clientBean) {
        mapper.insert(clientBean);
    }

    @Override
    public ClientBean findById(Integer clientId) {
        return mapper.selectById(clientId);
    }

    @Override
    public void update(Integer clientId, String principal, String phone, String manage) {
        ClientBean clientBean = new ClientBean();
        clientBean.setId(clientId);
        clientBean.setPrincipal(principal);
        clientBean.setPhone(phone);
        clientBean.setManage(manage);
        mapper.updateById(clientBean);
    }

    @Override
    public List<ClientBean> findAll() {
        return mapper.selectList(null);
    }
}
